<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<button>按钮</button>
</body>
<script>
document.querySelector('button').onclick = function() {
    // 发送post请求
    var xhr = new XMLHttpRequest
    xhr.open('post', 'http://localhost:3000/user')
    // xhr.send('key=value&key=value')

    // 注意：post请求要传递数据，就必须设置数据的格式
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')

    xhr.send('name=王五&password=456456&email=456456@qq.com')

    // xhr.send({
    //     name: '王五',
    //     password: '456456',
    //     email: '456456@qq.com'
    // })
    xhr.onreadystatechange = function() {
        if(xhr.readyState === 4) {
            if(xhr.status >= 200 && xhr.status < 300) {
                var msg = xhr.responseText
                console.log(msg);
            }
        }
    }
}
</script>
</html>